/**
* 系统管理 用户管理
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>字典管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :inline="true" :model="searchForm" class="user-search">
      <el-form-item label="">
        <!--<el-input size="small" v-model="searchForm.username" placeholder="输入用户名"></el-input>-->
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>

      </el-form-item>
    </el-form>

    <el-table size="small"  :data="tableData" highlight-current-row v-loading="tableLoading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center"  prop="tableName" label="表名称">
      </el-table-column>
      <el-table-column align="center"  prop="tableComment" label="表注释">
      </el-table-column>

      <el-table-column align="center"  prop="engine" label="引擎">
      </el-table-column>

      <el-table-column align="center"  prop="createTime" label="创建时间">
      </el-table-column>

      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button type="text"

                     icon="el-icon-search"
                     size="mini"
                     plain
                     @click="handleDown(scope.row,scope.index)">生成
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="page" @callFather="callFather"></Pagination>
    <el-dialog title="生成配置"
               :visible.sync="box"
               width="50%"
               lock-scroll>
      <div class="pull-auto">
        <el-form label-width="80px" ref="editForm" :model="editForm" >
          <el-form-item label="数据值" prop="value">
            <el-input size="small" v-model="editForm.tableName" auto-complete="off"  readonly="readonly" placeholder="请输入数据"></el-input>
          </el-form-item>
          <el-form-item label="类型" prop="type">
            <el-input size="small" v-model="editForm.packageName" auto-complete="off" placeholder="可为空,加载默认配置"></el-input>
          </el-form-item>
          <el-form-item label="排序" prop="sort">
            <el-input size="small" v-model="editForm.author" auto-complete="off"  placeholder="可为空,加载默认配置"></el-input>
          </el-form-item>
          <el-form-item label="标签名" prop="label">
            <el-input size="small" v-model="editForm.moduleName" auto-complete="off"  placeholder="可为空,加载默认配置"></el-input>
          </el-form-item>
          <el-form-item label="描述" prop="description">
            <el-input size="small" v-model="editForm.tablePrefix" auto-complete="off"  placeholder="可为空,加载默认配置"></el-input>
          </el-form-item>
          <el-form-item label="备注信息" prop="remarks">
            <el-input size="small" v-model="editForm.comments" auto-complete="off"  placeholder="可为空,加载默认配置"></el-input>
          </el-form-item>


        </el-form>

        <el-button size="small" @click='closeDialog()'>取消</el-button>
        <el-button size="small" type="primary"  class="title"  @click="gen()">生成</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {fetchList, handleDown} from '@/api/gen/gen'
  import {mapGetters} from 'vuex'
  import Pagination from '../../../components/Pagination'




  export default {
    name: 'code-generator',
    data() {
      return {
        editForm:{
          tableName:'',
          packageName:'',
          author:'',
          moduleName:'',
          tablePrefix:'',
          comments:'',
        },
        searchForm:{},
        tableData: [],

        box: false,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        },
        tableLoading: false

      }
    },
    created() {
      this.getList();
    },
    mounted: function () {
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    components: {
      Pagination
    },
    methods: {
      callFather(parm) {
        this.page.currentPage = parm.currentPage
        this.page.pageSize = parm.pageSize
        this.getList();
        //  this.getdata(this.formInline)
      },
      getList() {
        this.tableLoading = true
        fetchList(Object.assign({
          current: this.page.currentPage,
          size: this.page.pageSize
        },this.searchForm)).then(response => {
          this.tableData = response.data.data.records
          this.page.total = response.data.data.total
          this.tableLoading = false
        })
      },
      handleDown: function (row, index) {
        this.editForm.tableName = row.tableName
        this.box = true
      },
      /**
       * 刷新回调
       */
      refreshChange() {
        this.getList()
      },
      search() {
        this.getList()
      },
      gen(form, done) {
        handleDown(this.editForm).then(() => {
          this.box = false
        })

      }
    }
  }
</script>
<style scoped>
  .user-search {
    margin-top: 20px;
  }
  .userRole {
    width: 100%;
  }
</style>

